package com.niit.dao.impl;

import java.util.List;

import com.niit.bean.Mail;
import com.niit.bean.User;
import com.niit.dao.MailDao;
import com.niit.utils.DbUtil;

public class MailDaoImpl implements MailDao {

	private DbUtil util=new DbUtil();
	@Override
	public int add(Mail t) {
		String sql="insert into tb_mail(receiver,sender,content) values(?,?,?)";
		int a=util.update(sql, t.getReceiver(),t.getSender(),t.getContent());
		return a;
	}

	@Override
	public int delete(Mail t) {
		String sql="delete from tb_mail where id=? ";
		int a=util.update(sql, t.getId());
		return a;
	}

	@Override
	public int update(Mail t) {
		return 0;
	}

	@Override
	public List<Mail> findAll(int start, int end) {
		return null;
	}

	@Override
	public int findTotal() {
		String sql = "select count(*) from tb_mail where reveiver = ?";
		int count = util.selectCount(sql);
		return count;
	}

	@Override
	public List<Mail> findMails(User user, int start, int end) {
		String sql="select * from(select rownum r,tb_mail.* from tb_mail where receiver = ?) a where a.r>? and a.r<=?";
		List<Mail> list =util.select(sql, Mail.class,user.getUsername(), start,end);
		return list;
	}

}
